﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebNext.UI.Models.Tags;
using System.Collections.Specialized;
using WebNext.UI.Models.Admin;
using WebNext.UI.Models.Contact;

namespace WebNext.UI.Utils.ModelBinders
{
	public class ContactModelBinder : IModelBinder
	{
		public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
		{
			if (bindingContext.Model != null)
			{
				throw new NotImplementedException("Cannot update instances");
			}
			return this.BindTagModel(controllerContext.HttpContext.Request.Form);
		}

		private ContactViewModel BindTagModel(NameValueCollection form)
		{
			ContactViewModel contactViewModel = new ContactViewModel(false);
			contactViewModel.Sender = form["sender"];
			contactViewModel.Email = form["email"];
			contactViewModel.MessageContent = form["messageContent"];
			contactViewModel.CaptchaKey = form["captchaKey"];
			contactViewModel.CaptchaValue = form["captchaValue"];

			

			
			return contactViewModel;
		}
	}
}